package Top200;

import java.util.LinkedList;
import java.util.List;

/**
 * @author zhangmin
 * @create 2022-02-25 11:40
 * 回溯
 */
public class combine77 {

    List<List<Integer>> res=new LinkedList<>();
    void backtrack(int n,int start,int k,LinkedList<Integer> path){
        if (k==path.size()){
            res.add(new LinkedList<>(path));
            return;
        }
        for (int i = start; i <= n; i++) {
            path.add(i);
            backtrack(n,i+1,k,path);
            path.removeLast();
        }

    }
    public List<List<Integer>> combine(int n, int k) {
        backtrack(n,1,k,new LinkedList<>());
        return res;
    }
}
